const express = require('express');
const app = express();

const bodyParser = require('body-parser');

app.all('*', function(req, res, next) {
    res.header('Access-Control-Allow-Origin', "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header('Access-Control-Allow-Headers', 'Content-Type');
    res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
    res.header('Access-Control-Allow-Credentials', "true");
    res.header("X-Powered-By", ' 3.2.1');
    next();
});

// 注册路由
const loginRouter = require('./routes/logRoutes/loginRouter');
const registerRouter = require('./routes/logRoutes/registerRouter');

const setInfoRouter = require('./routes/infoRoutes/setInfoRouter');
const getInfoRouter = require('./routes/infoRoutes/getInfoRouter');

const getPartRouter = require('./routes/getPartRouter');

const getNoticeRouter = require('./routes/noticeRoutes/getNoticeRouter');
const addNoticeRouter = require('./routes/noticeRoutes/addNoticeRouter');
const delNoticeRouter = require('./routes/noticeRoutes/delNoticeRouter');

const getPostRouter = require('./routes/postRoutes/getPostRouter');
const getIDPostRouter = require('./routes/postRoutes/getIDPostRouter');
const addPostRouter = require('./routes/postRoutes/addPostRouter');
const delPostRouter = require('./routes/postRoutes/delPostRouter');

const getReplyRouter = require('./routes/replyRoutes/getReplyRouter');
const addReplyRouter = require('./routes/replyRoutes/addReplyRouter');
const delReplyRouter  = require('./routes/replyRoutes/delReplyRouter');

const getUserRouter = require('./routes/manageRoutes/getUserRouter');
const setStatusRouter = require('./routes/manageRoutes/setStatusRouter');
const setPowerRouter = require('./routes/manageRoutes/setPowerRouter');

const addLetterRouter = require('./routes/letterRoutes/addLetterRouter');
const getLetterRouter = require('./routes/letterRoutes/getLetterRouter');
const delLetterRouter = require('./routes/letterRoutes/delLetterRouter');

app.use(loginRouter);
app.use(registerRouter);

app.use(setInfoRouter);
app.use(getInfoRouter);

app.use(getPartRouter);

app.use(getNoticeRouter);
app.use(addNoticeRouter);
app.use(delNoticeRouter);

app.use(getPostRouter);
app.use(getIDPostRouter);
app.use(addPostRouter);
app.use(delPostRouter);

app.use(getReplyRouter);
app.use(addReplyRouter);
app.use(delReplyRouter);

app.use(getUserRouter);
app.use(setStatusRouter);
app.use(setPowerRouter);

app.use(addLetterRouter);
app.use(getLetterRouter);
app.use(delLetterRouter);

app.listen(8848,()=>{
    console.log('backend run at\n',
        ' http://localhost:8848/\n',
        ' http://127.0.0.1:8848/')
})
